package jdk8;

import java.util.Arrays;
import java.util.List;

public class StringDemo02 {
    public static void main(String[] args) {
        List<Integer> list1 = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
        //1.求集合中奇数的个数
        long count = list1.stream()
        .filter(i -> i % 2 == 1)
        .count();
        System.out.println(count);
        System.out.println("-------------------------------------------------------------");
        //2.求集合中，所有偶数的和
        //方案1
        int sum = list1.stream()
                        .filter(i -> i % 2 == 0)
                        .mapToInt(i -> i)
                        .sum();
        System.out.println(sum);
        System.out.println("-------------------------------------------------------------");
        //方案2
        sum=list1.stream().filter(i -> i % 2 == 0).reduce(0,(a,b) -> a + b);
        System.out.println(sum);
    }
}
